﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Scheduler;


namespace PhoneApp1
{
    public partial class AddRemainder : PhoneApplicationPage
    {
        public AddRemainder()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            String name = System.Guid.NewGuid().ToString();
            DateTime date = (DateTime)datePicker.Value;
            DateTime time = (DateTime)timePicker.Value;
            DateTime beginTime = date + time.TimeOfDay;
            DateTime expirationTime = new DateTime(beginTime.Year, beginTime.Month, beginTime.Day + 1, beginTime.Hour, beginTime.Minute, beginTime.Second);

            Reminder reminder = new Reminder(name);
            reminder.Title = tb_title.Text == String.Empty? "Remainder":tb_title.Text;
            reminder.Content = tb_content.Text;
            reminder.BeginTime = beginTime;
            reminder.ExpirationTime = expirationTime;
            reminder.RecurrenceType = RecurrenceInterval.None;
            reminder.NavigationUri = new Uri("/MainPage.xaml", UriKind.Relative);

            // Register the reminder with the system.
            try
            {
                ScheduledActionService.Add(reminder);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("Sorry, Invalide input!");
                return;
            }
            NavigationService.GoBack();

        }
    }
}